package wpspider.client.view.event;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JList;

import wpspider.client.model.Page;
import wpspider.client.view.ComponentRepository;

public class SearchButtonEH implements ActionListener {
	
	public void actionPerformed(ActionEvent event) {
		ComponentRepository repos = ComponentRepository.getInstance();
		JComboBox searchBox = (JComboBox) repos.getComponent("searchBox");
		String word = (String) searchBox.getSelectedItem();		
		if (word != null && 0 < word.length()) {
			searchBox.removeItem(word);
			int lastIndex = searchBox.getItemCount();
			if(10 < lastIndex) {
				searchBox.removeItemAt(lastIndex);					
			}
			searchBox.insertItemAt(word, 0);
			searchBox.setSelectedIndex(0);
//
//			List pages = PageModel.find(word);
//			JList pageList = (JList) repos.getComponent("pageList");
//			pageList.removeAll();
//			DefaultListModel model = (DefaultListModel) pageList.getModel();
//			for (Iterator iterator = pages.iterator(); iterator.hasNext(); ) {				
//				PageModel page = (PageModel) iterator.next();
//				model.addElement(page.getName());				
//			}
		}
	}
}
